package com.spzx.common.rabbit.config;

import com.spzx.common.core.constant.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

import java.util.HashMap;
import java.util.Map;

/**
 * Package: com.spzx.common.rabbit.config
 *
 * @author xiongkunYang
 * @description:
 * @since 2025/6/8 20:40
 */
//@SpringBootConfiguration
public class DelayedMqConfig {

    @Bean
    public Queue delayCancelOrderQueue() {
        // 第一个参数是创建的queue的名字，第二个参数是是否支持持久化
        return new Queue(MqConstants.QUEUE_CANCEL_ORDER, true);
    }

    @Bean
    public CustomExchange delayCancelOrderExchange() {
        // 参数列表
        Map<String, Object> args = new HashMap<>();
        // 延迟插件，延迟类型
        args.put("x-delayed-type", "direct");
        return new CustomExchange(MqConstants.EXCHANGE_CANCEL_ORDER, "x-delayed-message", true, false, args);
    }

    @Bean
    public Binding delayCancelOrderBinding() {
        return BindingBuilder.bind(delayCancelOrderQueue())
                .to(delayCancelOrderExchange())
                .with(MqConstants.ROUTING_CANCEL_ORDER).noargs();
    }
}